<?php
	/******Function : Warabi User Class******/
	/******Author : Feifei******/
	/******Date : 12/04/2008 ****/
	require_once('class.base.php');

	class dpfuser extends base{
		function insert_OneUser($name , $pwd , $auth , $nick){
			$name = $this->safePara($name);
			$pwd = $this->safePara($pwd);
			$auth = $this->safePara($auth);
			$nick = $this->safePara($nick);

			$obj = array(
				array("type" => ET_INSERT),
				array(
				"id"=>"",
				"username"=>$name,
				"userpwd"=>$pwd,
				"nickname"=>$nick,
				"auth"=>$auth
				)
			);
			$this->__set("execObj" , $obj);
			$lastid = $this->__insertOneResult();

			$returnstr = array(
				"id" => $lastid,
				"name" => $name,
				"pwd" => $pwd,
				"nick" => $nick,
				"auth" => $auth
			);

			$jsonreturn = json_encode($returnstr);
			echo $jsonreturn;
		}

		function update_OneUser($userid , $defh , $defw , $defq){
			$userid = $this->safePara($userid);
			$defh = $this->safePara($defh);
			$defw = $this->safePara($defw);
			$defq = $this->safePara($defq);

			$obj = array(
				array("type" => ET_UPDATE),
				array(
					"defWidth" => $defw,
					"defHeight" => $defh,
					"defQuality" => $defq
				),
				array("id" => $userid)
			);
			$this->__set("execObj" , $obj);
			if(!$this->__updateOneResult()){
				echo "fail";
			}
			else echo "succeed";
		}

		function delete_OneUser($userid){
			$userid = $this->safePara($userid);

			$obj = array(
				array("type" => ET_DELETE),
				array("id" => $userid)
			);
			$this->__set("execObj" , $obj);
			if($this->__deleteOneResult())
				echo $userid;
		}

		function get_AllUser_SelectResult($pid , $stel , $sdev , $smodel){
			$stel = $this->safePara($stel);
			$sdev = $this->safePara($sdev);
			$smodel = $this->safePara($smodel);
			
			$scon = empty($stel)?"":"and tel like '%".$stel."%'";
			$scon .= empty($sdev)?"":"and dev like '%".$sdev."%'";
			$scon .= empty($smodel)?"":"and model like '%".$smodel."%'";
			
			$limit = empty($scon)?("limit ".($pid*PER_NUM)." , ".PER_NUM):"";

			$obj = array(
				array("type" => ET_SELECT),
				array("*"),
				array("1"=>"1"),
				array(
					$scon,
					"order by id",
					$limit
				)
			);
			$this->__set("execObj" , $obj);
			return $this->__getAssocResult();
		}

		function get_AllUser_Num(){
			$obj = array(array("type" => ET_COUNT));
			$this->__set("execObj" , $obj);
			return $this->__getTableNum();
		}
	
		

		function showName(){
			return $this->tableName;
		}

	}

	$dpfuser = new dpfuser("dpf_user");

?>